package 华东交通大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import 湖北工业大学.HbGuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HDJu {
    public static void main(String[] args) throws IOException {
        HDJuBean hdJuBean = null;
        List<HDJuBean> hdJuBeans = new ArrayList<>();
        Connection connect = Jsoup.connect("http://dqxy.ecjtu.edu.cn/jsfc/sssds1.htm");
        Document post1 = connect.post();
        String attr1 = null;
        for (Element element : post1.getElementsByTag("table")) {
            Elements tr = element.getElementsByTag("tr");
            for (Element element1 : tr) {
                hdJuBean = new HDJuBean();
                if (element1.getElementsByTag("td").get(0).text().length() > 3 | element1.getElementsByTag("td").get(0).text().equals("姓名")) {
                    continue;
                } else {
                    //姓名
//                    System.out.println(element1.getElementsByTag("td").get(0).text());
                    hdJuBean.setT_name(element1.getElementsByTag("td").get(0).text());
                    //链接
                    String attr = element1.getElementsByTag("a").attr("href");
                    attr1 = attr.substring(3, attr.length());
                    Connection connect1 = Jsoup.connect("http://dqxy.ecjtu.edu.cn/" + attr1);
                    Document post11 = connect1.post();
                    for (Element firstRow : post11.getElementsByClass("firstRow")) {
                        if (firstRow.text().length() == 0) {
                            System.out.println("null");
                        } else {
                            hdJuBean.setInfo(firstRow.text());
//                            System.out.println(firstRow.text());
                        }
                    }

                }
                hdJuBeans.add(hdJuBean);
            }
        }


        EasyExcel.write("src/HDJu.xlsx", HDJuBean.class).sheet("user").doWrite(hdJuBeans);

    }
}
